package com.fushenlan.epidemicControl.controller;


/**
 * @author coolMan
 * @title: NucleicDetectionController
 * @projectName 核酸检测相关
 * @description:
 * @date 2022/4/20
 */

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fushenlan.commons.GeneralResponse;
import com.fushenlan.dto.*;
import com.fushenlan.epidemicControl.service.NucleinDetectionApplyRecordService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@Api(tags = "app核酸检测")
@Slf4j
@RestController
@RequestMapping("/nucleic")
public class NucleicDetectionController {

    @Autowired
    private NucleinDetectionApplyRecordService nucleinDetectionApplyRecordService;

    /**
     * 个人页面核酸检测记录查询
     * @return
     */
    @GetMapping("/personalDetection")
    public GeneralResponse<PersonalDetectionRespDTO> personalDetection() {
        try {
            return nucleinDetectionApplyRecordService.personalDetection();
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 个人页面核酸检测查询结果
     * @param recordId  申请记录id
     * @return
     */
    @GetMapping("/personalDetectionResult")
    public GeneralResponse<List<PersonalDetectionResultRespDTO>> personalDetectionResult(@RequestParam("recordId")Long recordId) {
        try {
            return nucleinDetectionApplyRecordService.personalDetectionResult(recordId);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }


    /**
     * 个人页面核酸检测提交结果
     * @param
     * @param
     * @return
     */
    @PostMapping("/personalDetectionResultCommit")
    public GeneralResponse personalDetectionResultCommit(@RequestBody List<PersonalDetectionResultRespDTO> personalDetectionResultRespDTOS) {
        try {
            return nucleinDetectionApplyRecordService.personalDetectionResultCommit(personalDetectionResultRespDTOS);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 居委会核酸检测记录统计主页
     * @return
     */
    @GetMapping("/neighborhoodDetectionCensus")
    public GeneralResponse<NeighborhoodDetectionCensusRespDTO> neighborhoodDetectionCensus() {
        try {
            return nucleinDetectionApplyRecordService.neighborhoodDetectionCensus();
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }


    /**
     * 未转运信息汇总人员查找
     * @param name  姓名
     * @param community  小区
     * @param status  1-未转运 2-已转运 3-检测阳性
     * @return
     */
    @GetMapping("/notTransportCensus")
    public GeneralResponse<List<PersonalInfoRespDTO>> notTransportCensus(
                                                                         @RequestParam(required = false,value = "name") String name,
                                                                         @RequestParam(required = false,value = "community") Long community,
                                                                         @RequestParam("status") Integer status) {
        //        累计已转运包括已自愈 已转运不包括已治愈
        try {
            return nucleinDetectionApplyRecordService.notTransportCensus( name, community, status);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 小区核酸检测记录统计主页
     * @param community  小区
     * @return
     */
    @GetMapping("/communityDetectionCensus")
    public GeneralResponse<NeighborhoodDetectionCensusRespDTO> communityDetectionCensus(@RequestParam(required = false,value = "community") Long community) {
        try {
            return nucleinDetectionApplyRecordService.communityDetectionCensus( community);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 小区核酸检测记录统计详情
     * @param detectionId  核酸检测记录id
     * @param community  小区
     * @param name  姓名搜索
     * @param status  1-未检测 2-结果未登记 3-已检测  4-结果已登记 5-检测阳性 6-未转运 7-已转运 8-已治愈
     * @param pageSize  每页显示条数
     * @param pagerNum  当前页
     * @return
     */
    @GetMapping("/communityDetectionInfo")
    public GeneralResponse<IPage<PersonalInfoRespDTO>> communityDetectionInfo(@RequestParam("detectionId") Long detectionId,
                                                                             @RequestParam(required = false,value = "community") Long community,
                                                                             @RequestParam(required = false,value = "name") String name,
                                                                             @RequestParam("status") Integer status,
                                                                             @RequestParam("pageSize") Integer pageSize,
                                                                             @RequestParam("pagerNum") Integer pagerNum) {
        try {
            return nucleinDetectionApplyRecordService.communityDetectionInfo(detectionId, community, name, status, pageSize, pagerNum);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }


    /**
     * 转运治愈登记
     */
    @PostMapping("/personalStatusCommit")
    public GeneralResponse personalStatusCommit(@RequestBody PersonalStatusCommitReqDTO personalStatusCommitReqDTO) {
        try {
            return nucleinDetectionApplyRecordService.personalStatusCommit(personalStatusCommitReqDTO);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 密接查询
     * @param userId  用户id
     * @param detectionId  核酸申请记录id
     * @return
     */
    @GetMapping("/closeContactInfo")
    public GeneralResponse<List<PersonalInfoRespDTO>> closeContactInfo(@RequestParam("userId") Long userId,
                                                                       @RequestParam(required = false,value = "detectionId") Long detectionId) {
        try {
            return nucleinDetectionApplyRecordService.closeContactInfo(userId, detectionId);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 获取当前居委所有的小区
     * @param userId  用户id
     * @return
     */
    @GetMapping("/getCommunityList")
    public GeneralResponse<List<CommunityDTO>> getCommunityList(@RequestParam("userId") Long userId) {
        try {
            return nucleinDetectionApplyRecordService.getCommunityList(userId);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 获取当前居委所有的小区
     * @return
     */
    @GetMapping("/getAllInformation")
    public GeneralResponse<AllInformationInfoDTO> getAllInformation() {
        try {
            AllInformationInfoDTO allInformationInfoDTO=new AllInformationInfoDTO();
            allInformationInfoDTO.setNowDateTime(LocalDateTime.now());
            return GeneralResponse.success(allInformationInfoDTO);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 获取当前核酸检测记录二维码的二维码
     * @param detectionId
     * @return
     */
    @GetMapping("/getQRCode")
    public GeneralResponse<String> getQRCode(@RequestParam("detectionId")Long detectionId) {
        try {
            return nucleinDetectionApplyRecordService.getQRCode(detectionId);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }

    /**
     * 个人页面核酸检测提交检测状态
     * @param
     * @param
     * @return
     */
    @PostMapping("/personalDetectionCommit")
    public GeneralResponse personalDetectionCommit(@RequestBody List<PersonalDetectionResultRespDTO> personalDetectionResultRespDTOS) {
        try {
            return nucleinDetectionApplyRecordService.personalDetectionCommit(personalDetectionResultRespDTOS);
        }catch (Exception e){
            log.error(e.getMessage());
            return GeneralResponse.fail();
        }
    }
}
